package com.pin.si.www.example.controller;

import com.pin.si.www.common.exception.utils.ExceptionUtils;
import com.pin.si.www.common.pojo.result.CommonResult;
import com.pin.si.www.common.pojo.result.ErrorCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/log-test")
@Tag(name = "日志测试接口")
public class LogTestController {

    /**
     * GET请求测试方法
     */
    @Operation(summary = "GET请求测试")
    @GetMapping("/get")
    public CommonResult<String> testGetRequest() {
        return CommonResult.success("GET请求测试成功");
    }

    /**
     * POST请求测试方法
     */
    @Operation(summary = "POST请求测试", description = "POST请求测试参数：data")
    @PostMapping("/post")
    public CommonResult<String> testPostRequest(
            @Parameter(description = "POST请求测试参数") String data) {
        return CommonResult.success("POST请求测试成功：" + data);
    }

    /**
     * 测试全局异常拦截
     */
    @Operation(summary = "测试全局异常拦截")
    @GetMapping("/error")
    public CommonResult<Object> testError() {
        ExceptionUtils.throwIsNotNull(new Object(), new ErrorCode(500, "测试异常日志记录"));
        return CommonResult.success();
    }

    /**
     * 文件上传测试方法
     */
    @Operation(summary = "文件上传测试")
    @PostMapping("/upload")
    public CommonResult<String> testUploadFile(
            @Parameter(description = "文件对象") MultipartFile file) {
        return CommonResult.success("文件上传成功，文件名: " + file.getOriginalFilename() + "，大小: " + file.getSize() + " bytes");
    }

    @Data
    @Schema(description = "实体类测试参数")
    public static class ExampleEntity {
        @Schema(description = "名称")
        private String name;
        @Schema(description = "年龄")
        private int age;
    }

    @Operation(summary = "实体类测试")
    @PostMapping("/entity")
    public CommonResult<ExampleEntity> testEntity(@Parameter(description = "实体类") @RequestBody ExampleEntity entity) {
        return CommonResult.success(entity);
    }
}
